package model.jgap;

import model.trader.MomentumTrader;
import model.trader.MarketMaker;
import model.trader.Trader;

import org.jgap.Configuration;
import org.jgap.Gene;
import org.jgap.InvalidConfigurationException;
import org.jgap.impl.CompositeGene;
import org.jgap.impl.DoubleGene;
import org.jgap.impl.IntegerGene;

public class OpportunistGene extends CompositeGene implements TraderGene {

	public OpportunistGene(Configuration conf) throws InvalidConfigurationException {
		super(conf);
		
		//Shift required to trade.. up to 200% movement in one period!
		addGene(new DoubleGene(conf,0.001,2));
		
		//Trade value..
		addGene(new IntegerGene(conf,0,100000));
	}
	
	
	public Trader getTrader() {
		double shiftRequiredToTrade = ((DoubleGene)geneAt(0)).doubleValue();
		int tradeValue = ((IntegerGene)geneAt(1)).intValue();
		return new MarketMaker(shiftRequiredToTrade,tradeValue);
	}
	
	//AMLOW: dodgy copy paste all over the custom gene types..
	protected Gene newGeneInternal() {
	    try {
	      OpportunistGene compositeGene = new OpportunistGene(getConfiguration());
	      compositeGene.setConstraintChecker(getConstraintChecker());
	      Gene gene;
//	      int geneSize = m_genes.size();
//	      for (int i = 0; i < geneSize; i++) {
//	        gene = (Gene) m_genes.get(i);
//	        compositeGene.addGene(gene.newGene(), false);
//	      }
	      return compositeGene;
	    }
	    catch (InvalidConfigurationException iex) {
	      throw new IllegalStateException(iex.getMessage());
	    }
	  }
	
	
}
